package com.example.wechat;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class MyService2 extends Service {
    MediaPlayer player;
    int[] musics={
            R.raw.music1,
            R.raw.music2,
            R.raw.music3
    };
    public MyService2() {

    }

    @Override
    public IBinder onBind(Intent intent) {
        MyBinder myBinder=new MyBinder();
        Log.d("jd","Myservice2:onBind");
        return myBinder;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("jd","Myservice2:onCreate");
        player = MediaPlayer.create(this, musics[0]);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d("jd","Myservice2:onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }



    //看生命周期
    @Override
    public void onDestroy() {
        player.stop();
        player.release();
        super.onDestroy();
        Log.d("jd","MyService2:onDestroy...");
    }
    class MyBinder extends Binder{
        public MyBinder() {
        }
        public void Todo(){
            player.start();//放歌
            Log.d("jd","Myservice2:Todo");

        }
    }


    }


